package com.zzyl.service.impl;

import com.zzyl.dto.BedDto;
import com.zzyl.entity.live.Bed;
import com.zzyl.mapper.BedMapper;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class BedServiceImpl implements BedService {
	
	@Autowired
	private BedMapper bedMapper;
	
	@Override
	public List<BedVo> getBedsByRoomId(Long roomId) {
		return bedMapper.getBedsByRoomId(roomId);
	}
/*
*
* */
	@Override
	public void saveOrUpdate(BedDto bedDto) {
		Bed bed = new Bed();
		BeanUtils.copyProperties(bedDto, bed);
		bed.setUpdateTime(LocalDateTime.now());
		bed.setCreateTime(LocalDateTime.now());
		bed.setBedStatus(0);
		bedMapper.saveOrUpdate(bed);
	}

	@Override
	public BedVo readAllBed(Integer id) {
			BedVo bedVo = bedMapper.readAllBed(id);
			return bedVo;
	}

	@Override
	public void updateBed(BedVo bedVo) {
		bedVo.setUpdateTime(LocalDateTime.now());
		bedMapper.updateBed(bedVo);
	}

	@Override
	public void deleteBed(Integer id) {
		bedMapper.deleteBed(id);
	}
}

